package name.huzhenbo.java.klass;

class InitializeSequence {
    private static final StaticField COUNTER = new StaticField();

    public static StaticField counter() {
        return (StaticField)COUNTER.clone();
    }

    static {
        System.out.println("static block initialization");
        COUNTER.count++;
    }

    public InitializeSequence() {
        System.out.println("constructor initialize");
        COUNTER.count++;
    }

    static final class StaticField implements Cloneable {
        private int count = 0;

        public StaticField() {
            System.out.println("static field initialization");
        }

        public int getCount() {
            return count;
        }

        @Override
        public Object clone(){
            try {
                return super.clone();
            } catch (CloneNotSupportedException e) {
                return null;
            }
        }
    }

}
